package cn.coldleaf.wiki.configure;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * @datetime 2023/10/15 下午12:54
 * @user cold
 **/
@Data
@Configuration
@EnableOpenApi
@ConfigurationProperties(prefix = "springfox.documentation")
public class SwaggerConfig {
    private String title;
    private String version;
    private Boolean enabled;

    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title(title)
                .version(version)
                .contact(new Contact("cold","https://www.coldleaf.cn","2509284099@qq.com"))
                .build();
    }

    @Bean
    public Docket docket(){
        return new Docket(DocumentationType.OAS_30)
                .enable(enabled)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("cn.coldleaf.wiki.controllers"))
                .paths(PathSelectors.any())
                .build();
    }
}
